<?php
defined('IN_CMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
pc_base::load_sys_class('form','',0);
class area extends admin  {
	function __construct() {
        parent::__construct();
		$this->db = pc_base::load_model("linkage_model");
	}
	
	/**
	 * 列表
	 */
	function mylist(){
		$page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
        switch ($_POST['action']){
            case "add":
                $item = $_POST['item'];
                $id = $this->db->insert($item,true);
                break;
            case "edit":
                $id = $_POST['id'];
                $item = $_POST['item'];
                $this->db->update($item,$where = 'id = '.$id);
                break;
        }


        $lists = $this->db->select($where='');
        $listsKV = $this->setKVList($lists, 'linkageid', 'name');
        
        $whereSql = '';
        $lists = $this->db->listinfo($whereSql,$order = '',$page);
        $pages = $this->db->pages;

		include $this->admin_tpl('myarealist');
	}
	
	
	function myadd(){
		$lists = $this->db->select($where='');
		include $this->admin_tpl('myareaadd');
		
	}
	
	function myedit(){
		$lists = $this->db->select($where='');
		$id = $_GET['id'];
		$whereSql = array('id'=>$id);
		$item = $this->db->get_one($whereSql);
		
		include $this->admin_tpl('myareaedit');
	}
	
	function mydelone(){
		$id = $_GET['id'];
		$this->db->delete($where = 'id = '.$id);
		$this->mylist();
	}

	private function setKVList($lists,$keyName,$valueName){
		$kvList = array();
		foreach ($lists as $item){
			$kvList[$item[$keyName]]=$item[$valueName];
		}
		return $kvList;
	}
	
}

?>